package com.hc.util;

import com.hc.ftp.ConfigureActivity;
import com.hc.ftp.Defaults;
import com.hc.ftp.FTPServerService;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

public class FtpManager {

	private Context context;
	public final static String USERNAME = "username";
	public final static String PASSWORD = "password";
	public final static String PORTNUM = "portNum";
	public final static String CHROOTDIR = "chrootDir";
	public final static String ACCEPT_WIFI = "allowWifi";
	public final static String ACCEPT_NET = "allowNet";
	public final static String STAY_AWAKE = "stayAwake";

	public FtpManager() {

	}

	// * In order to choose whether to stop or start the server, we check
	// * the text on the button to see which action the user was
	// * expecting.
	// */
	// String startString = getString(R.string.start_server);
	// String stopString = getString(R.string.stop_server);
	// String buttonText = startStopButton.getText().toString();
	// if(buttonText.equals(startString)) {
	// /* The button had the "start server" text */
	// if(!FTPServerService.isRunning()) {
	// warnIfNoExternalStorage();
	// context.startService(intent);
	// }
	// } else if (buttonText.equals(stopString)) {
	// /* The button had the "stop server" text. We stop the server now. */
	// context.stopService(intent);
	private Intent intent;
	
	public static FtpManager ftp = null;
	
	public FtpManager(Context context) {
		this.context = context;
		intent = new Intent(context, FTPServerService.class);
		initParams();
		ftp = this;
	}
	

	private void initParams() {
		SharedPreferences settings = context.getSharedPreferences(
				Defaults.getSettingsName(), Defaults.getSettingsMode());
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(USERNAME, "admin");
		editor.putString(PASSWORD, "admin");
		editor.putInt(PORTNUM, 2121);
		editor.putString(CHROOTDIR, "/sdcard/hcftp");
		editor.putBoolean(ACCEPT_WIFI, true);
		editor.putBoolean(ACCEPT_NET, false);
		editor.putBoolean(STAY_AWAKE, false);
		editor.commit();
	}

	public void startFtp() {
		if (!FTPServerService.isRunning()) {
//			context.bindService(intent,,)
			context.startService(intent);
		}
	}

	public void stopFtp() {
		Intent intent = new Intent(context, com.hc.ftp.FTPServerService.class);
		boolean isStop = context.stopService(intent);
		System.out.println("---isStop---"+isStop);
	}
}
